<template>
    <div class="box">
        <div class="header">
            <van-search v-model="keyword" show-action placeholder="请输入搜索关键词" @search="onSearch">
                <template #action>
                    <div @click="onSearch">搜索</div>
                </template>
            </van-search>
        </div>
        <div class="content">
            <h3>最近搜索</h3>

            <h3>热门搜索</h3>
            <ul class="ul">
                <li class="li" v-for="item in hotlist" :key="item.wordid">
                    {{ item.keyword }}
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
import Vue from 'vue'
import { Search, Toast } from 'vant'
import { hotseach } from '@/api/search'

Vue.use(Search)
export default {
    data() {
        return {
            keyword: '',
            hotlist: [],
        }
    },
    mounted() {
        // 热门搜索
        hotseach().then(res => {
            console.log(res);
            this.hotlist = res.data
            console.log(this.hotlist);
        })
    },
    methods: {
        onSearch() {
            if (this.keyword == '') {
                Toast('搜索框不能为空')
            } else {
                this.$router.push('/result/' + this.keyword)
            }
        }
    },
}
</script>
<style scoped>

.van-search {
    padding: 5px 12px
}

.ul {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    padding-left: 10px;
}

.li {
    background-color: #ccc;
    width: 25%;
    height: 40px;
    line-height: 40px;
    margin: 10px;
    text-align: center;
    box-sizing: border-box;
}
</style>
